From e91ecf39b8d27b3ef7ab2018a8dbb303634d7cf1 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Mon, 30 Oct 2006 20:08:04 +0000 Subject: [PATCH] Check in new transformation filter "transform". --- Makefile.in | 3 +- filter_vecs.c | 6 + reference/transform-rte.gpx | 783 +++++++++++++++++++++++++++++++++++ reference/transform-wpt.gpx | 378 +++++++++++++++++ testo | 10 + transform.c | 194 +++++++++ xmldoc/filters/transform.xml | 19 + 7 files changed, 1392 insertions(+), 1 deletion(-) create mode 100644 reference/transform-rte.gpx create mode 100644 reference/transform-wpt.gpx create mode 100644 transform.c create mode 100644 xmldoc/filters/transform.xml diff --git a/Makefile.in b/Makefile.in index 2c674fb18..c6c6aff56 100644 --- a/Makefile.in +++ b/Makefile.in @@ -57,7 +57,7 @@ FMTS=magproto.o gpx.o geo.o mapsend.o mapsource.o garmin_tables.o \ FILTERS=position.o radius.o duplicate.o arcdist.o polygon.o smplrout.o \ reverse_route.o sort.o stackfilter.o trackfilter.o discard.o \ - nukedata.o interpolate.o + nukedata.o interpolate.o transform.o JEEPS=jeeps/gpsapp.o jeeps/gpscom.o \ jeeps/gpsmath.o jeeps/gpsmem.o \ @@ -572,6 +572,7 @@ tpo.o: tpo.c defs.h config.h queue.h gbtypes.h zlib/zlib.h zlib/zconf.h \ trackfilter.o: trackfilter.c defs.h config.h queue.h gbtypes.h \ zlib/zlib.h zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h \ filterdefs.h strptime.h grtcirc.h +transform.o: transform.c defs.h filterdefs.h unicsv.o: unicsv.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \ zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h csv_util.h \ jeeps/gpsmath.h jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h \ diff --git a/filter_vecs.c b/filter_vecs.c index 2dc2f42a8..8dee6d560 100644 --- a/filter_vecs.c +++ b/filter_vecs.c @@ -42,6 +42,7 @@ extern filter_vecs_t trackfilter_vecs; extern filter_vecs_t discard_vecs; extern filter_vecs_t nuke_vecs; extern filter_vecs_t interpolatefilt_vecs; +extern filter_vecs_t transform_vecs; static fl_vecs_t filter_vec_list[] = { @@ -111,6 +112,11 @@ fl_vecs_t filter_vec_list[] = { "track", "Manipulate track lists" }, + { + &transform_vecs, + "transform", + "Transformate waypoints into a route, tracks into routes, ..." + }, #endif { NULL, diff --git a/reference/transform-rte.gpx b/reference/transform-rte.gpx new file mode 100644 index 000000000..f9995b15d --- /dev/null +++ b/reference/transform-rte.gpx @@ -0,0 +1,783 @@ + + + + + + + 44.586548 + + 5066 + 5066 + 5066 + Crossing +Crossing + + + 57.607200 + + 5067 + 5067 + 5067 + Dot +Intersection + + + 44.826904 + + 5096 + 5096 + 5096 + Dot +Dot + + + 50.594727 + + 5142 + 5142 + 5142 + Dot +Dot + + + 127.711200 + + 5156 + 5156 + 5156 + Dot +Intersection + + + 96.926400 + + 5224 + 5224 + 5224 + Dot +Intersection + + + 82.600800 + + 5229 + 5229 + 5229 + Dot +Intersection + + + 82.905600 + + 5237 + 5237 + 5237 + Dot +Intersection + + + 66.696655 + + 5254 + 5254 + 5254 + Dot +Dot + + + 74.627442 + + 5258 + 5258 + 5258 + Dot +Dot + + + 65.254761 + + 5264 + 5264 + 5264 + Dot +Dot + + + 77.419200 + + 526708 + 526708 + 526708 + Dot +Intersection + + + 74.676000 + + 526750 + 526750 + 526750 + Dot +Intersection + + + 78.713135 + + 527614 + 527614 + 527614 + Dot +Dot + + + 78.713135 + + 527631 + 527631 + 527631 + Dot +Dot + + + 68.275200 + + 5278 + 5278 + 5278 + Dot +Intersection + + + 64.008000 + + 5289 + 5289 + 5289 + Dot +Intersection + + + 52.997925 + + 5374FIRE + 5374FIRE + 5374FIRE + Dot +Dot + + + 56.388000 + + 5376 + 5376 + 5376 + Dot +Intersection + + + 56.388000 + + 6006 + 600698 + 600698 + Dot +Intersection + + + 46.028564 + + 6006BLUE + 6006BLUE + 6006BLUE + Dot +Dot + + + 37.616943 + + 6014MEADOW + 6014MEADOW + 6014MEADOW + Dot +Dot + + + 56.388000 + + 6029 + 6029 + 6029 + Dot +Intersection + + + 50.292000 + + 6053 + 6053 + 6053 + Dot +Intersection + + + 25.603200 + + 6066 + 6066 + 6066 + Dot +Intersection + + + 34.442400 + + 6067 + 6067 + 6067 + Dot +Intersection + + + 30.480000 + + 6071 + 6071 + 6071 + Dot +Intersection + + + 15.240000 + + 6073 + 6073 + 6073 + Dot +Intersection + + + 37.795200 + + 6084 + 6084 + 6084 + Dot +Intersection + + + 64.008000 + + 6130 + 6130 + 6130 + Dot +Intersection + + + 64.008000 + + 6131 + 6131 + 6131 + Dot +Intersection + + + 62.788800 + + 6153 + 6153 + 6153 + Dot +Intersection + + + 55.473600 + + 6171 + 6171 + 6171 + Dot +Intersection + + + 62.484000 + + 6176 + 6176 + 6176 + Dot +Intersection + + + 62.179200 + + 6177 + 6177 + 6177 + Dot +Intersection + + + 69.799200 + + 6272 + 6272 + 6272 + Dot +Intersection + + + 73.152000 + + 6272 + 6272 + 6272 + Dot +Intersection + + + 70.104000 + + 6278 + 6278 + 6278 + Dot +Intersection + + + 57.564209 + + 6280 + 6280 + 6280 + Dot +Dot + + + 66.696655 + + 6283 + 6283 + 6283 + Dot +Dot + + + 72.945191 + + 6289 + 6289 + 6289 + Dot +Dot + + + 72.847200 + + 6297 + 6297 + 6297 + Dot +Intersection + + + 53.644800 + + 6328 + 6328 + 6328 + Dot +Intersection + + + 43.891200 + + 6354 + 6354 + 6354 + Dot +Intersection + + + 48.768000 + + 635722 + 635722 + 635722 + Dot +Intersection + + + 49.072800 + + 635783 + 635783 + 635783 + Dot +Intersection + + + 62.484000 + + 6373 + 6373 + 6373 + Dot +Intersection + + + 3.962400 + + 6634 + 6634 + 6634 + Dot +Intersection + + + 13.411200 + + 6979 + 6979 + 6979 + Dot +Intersection + + + 34.012085 + + 6997 + 6997 + 6997 + Dot +Dot + + + 87.782400 + + BEAR HILL + BEAR HILL TOWER + Bear Hill Tower + Tall Tower +Tower + + + 23.469600 + + BELLEVUE + BELLEVUE + Bellevue Parking Lot + Parking Area +Parking + + + 43.384766 + + 6016 + Bike Loop Connector + Bike Loop Connector + Waypoint +Intersection + + + 89.916000 + + 5236BRIDGE + Bridge + Bridge + Bridge +Bridge + + + 55.473600 + + 5376BRIDGE + Bridge + Bridge + Bridge +Bridge + + + 52.730400 + + 6181CROSS + Crossing + Crossing + Crossing +Crossing + + + 45.110400 + + 6042CROSS + Crossing + Crossing + Crossing +Crossing + + + DARKHOLLPO + Dark Hollow Pond + Dark Hollow Pond + Fishing Area + + + 56.083200 + + 6121DEAD + Dead End + Dead End + Danger Area +Dead End + + + 117.043200 + + 5179DEAD + Dead End + Dead End + Danger Area +Dead End + + + 69.494400 + + 5299DEAD + Dead End + Dead End + Danger Area +Dead End + + + 56.997600 + + 5376DEAD + Dead End + Dead End + Danger Area +Dead End + + + 46.939200 + + 6353DEAD + Dead End + Dead End + Danger Area +Dead End + + + 61.264800 + + 6155DEAD + Dead End + Dead End + Danger Area +Dead End + + + 110.947200 + + GATE14 + Gate 14 + Gate 14 + Truck Stop +Road + + + 77.724000 + + GATE16 + Gate 16 + Gate 16 + Truck Stop +Road + + + 65.836800 + + GATE17 + Gate 17 + Gate 17 + Truck Stop +Road + + + 57.302400 + + GATE19 + Gate 19 + Gate 19 + Truck Stop +Road + + + 49.377600 + + GATE21 + Gate 21 + Gate 21 + Truck Stop +Road + + + 81.076800 + + GATE24 + Gate 24 + Gate 24 + Truck Stop +Road + + + 21.515015 + + GATE5 + Gate 5 + Gate 5 + Truck Stop +Truck Stop + + + 26.561890 + + GATE6 + Gate 6 + Gate 6 + Waypoint +Trail Head + + + 32.004000 + + 6077LOGS + Log Crossing + Log Crossing + Amusement Park +Obstacle + + + 119.809082 + + 5148NANEPA + Nanepashemet Road Crossing + Nanepashemet Road Crossing + Waypoint +Trail Head + + + 73.761600 + + 5267OBSTAC + Obstacle + Obstacle + Amusement Park +Obstacle + + + 45.307495 + + PANTHRCAVE + Panther Cave + Panther Cave + Tunnel +Tunnel + + + 77.992066 + + 5252PURPLE + Purple Rock Hill + Purple Rock Hill + Summit +Summit + + + 67.970400 + + 5287WATER + Reservoir + Reservoir + Swimming Area +Reservoir + + + 81.076800 + + 5239ROAD + Road + Road + Truck Stop +Road + + + 67.360800 + + 5278ROAD + Road + Road + Truck Stop +Road + + + 53.949600 + + 5058ROAD + ROAD CROSSING + Road Crossing + Dot +Road Crossing + + + 69.799200 + + SHEEPFOLD + Sheepfold Parking Lot + Sheepfold Parking Lot + Parking Area +Parking + + + 64.008000 + + SOAPBOX + Soap Box Derby Track + Soap Box Derby Track + Cemetery +Intersection + + + 64.533692 + + 5376STREAM + Stream Crossing + Stream Crossing + Bridge +Bridge + + + 61.649902 + + 5144SUMMIT + Summit + Summit + Summit +Summit + + + 67.360800 + + 5150TANK + WATER TANK + Water Tank + Museum +Water Tank + + + diff --git a/reference/transform-wpt.gpx b/reference/transform-wpt.gpx new file mode 100644 index 000000000..7e01e9532 --- /dev/null +++ b/reference/transform-wpt.gpx @@ -0,0 +1,378 @@ + + + + + + 23.469600 + + BELLEVUE + BELLEVUE + Bellevue Parking Lot + Parking Area + + + 26.561890 + + GATE6 + Gate 6 + Gate 6 + Waypoint + + + 45.307495 + + PANTHRCAVE + Panther Cave + Panther Cave + Tunnel + + + 37.616943 + + 6014MEADOW + 6014MEADOW + 6014MEADOW + Dot + + + 56.388000 + + 6006 + 600698 + 600698 + Dot + + + 46.028564 + + 6006BLUE + 6006BLUE + 6006BLUE + Dot + + + 44.826904 + + 5096 + 5096 + 5096 + Dot + + + 44.586548 + + 5066 + 5066 + 5066 + Crossing + + + 57.607200 + + 5067 + 5067 + 5067 + Dot + + + 53.949600 + + 5058ROAD + ROAD CROSSING + Road Crossing + Dot + + + 67.360800 + + 5150TANK + WATER TANK + Water Tank + Museum + + + 50.594727 + + 5142 + 5142 + 5142 + Dot + + + 61.649902 + + 5144SUMMIT + Summit + Summit + Summit + + + 127.711200 + + 5156 + 5156 + 5156 + Dot + + + 119.809082 + + 5148NANEPA + Nanepashemet Road Crossing + Nanepashemet Road Crossing + Waypoint + + + 74.627442 + + 5258 + 5258 + 5258 + Dot + + + 77.992066 + + 5252PURPLE + Purple Rock Hill + Purple Rock Hill + Summit + + + 78.713135 + + 527631 + 527631 + 527631 + Dot + + + 78.713135 + + 527614 + 527614 + 527614 + Dot + + + 73.761600 + + 5267OBSTAC + Obstacle + Obstacle + Amusement Park + + + 68.275200 + + 5278 + 5278 + 5278 + Dot + + + 64.008000 + + 5289 + 5289 + 5289 + Dot + + + 52.997925 + + 5374FIRE + 5374FIRE + 5374FIRE + Dot + + + 56.388000 + + 5376 + 5376 + 5376 + Dot + + + 64.533692 + + 5376STREAM + Stream Crossing + Stream Crossing + Bridge + + + 53.644800 + + 6328 + 6328 + 6328 + Dot + + + 48.768000 + + 635722 + 635722 + 635722 + Dot + + + 49.072800 + + 635783 + 635783 + 635783 + Dot + + + 62.484000 + + 6373 + 6373 + 6373 + Dot + + + 87.782400 + + BEAR HILL + BEAR HILL TOWER + Bear Hill Tower + Tall Tower + + + 72.945191 + + 6289 + 6289 + 6289 + Dot + + + 72.847200 + + 6297 + 6297 + 6297 + Dot + + + 66.696655 + + 6283 + 6283 + 6283 + Dot + + + 57.564209 + + 6280 + 6280 + 6280 + Dot + + + 62.179200 + + 6177 + 6177 + 6177 + Dot + + + 62.484000 + + 6176 + 6176 + 6176 + Dot + + + 62.788800 + + 6153 + 6153 + 6153 + Dot + + + 55.473600 + + 6171 + 6171 + 6171 + Dot + + + 64.008000 + + 6131 + 6131 + 6131 + Dot + + + 64.008000 + + 6130 + 6130 + 6130 + Dot + + + 56.388000 + + 6029 + 6029 + 6029 + Dot + + + 56.388000 + + 6006 + 600698 + 600698 + Dot + + + 37.616943 + + 6014MEADOW + 6014MEADOW + 6014MEADOW + Dot + + + 45.307495 + + PANTHRCAVE + Panther Cave + Panther Cave + Tunnel + + + 26.561890 + + GATE6 + Gate 6 + Gate 6 + Waypoint + + + 23.469600 + + BELLEVUE + BELLEVUE + Bellevue Parking Lot + Parking Area + + diff --git a/testo b/testo index f4b94e185..6c45e8b43 100755 --- a/testo +++ b/testo @@ -1133,4 +1133,14 @@ compare ${TMPDIR}/ge-gc.kml ${REFERENCE}/earth-gc.kml ${PNAME} -i gpx -f ${REFERENCE}/expertgps.gpx -o kml -F ${TMPDIR}/ge-eg.kml compare ${TMPDIR}/ge-eg.kml ${REFERENCE}/earth-expertgps.kml +# +# Transformation filter (transform) tests +# +rm -f ${TMPDIR}/transform* +${PNAME} -i gpx -f ${REFERENCE}/expertgps.gpx -x nuketypes,routes,tracks -x transform,rte=wpt,del=y -o gpx -F ${TMPDIR}/transform-rte.gpx +compare ${TMPDIR}/transform-rte.gpx ${REFERENCE}/transform-rte.gpx +${PNAME} -i gpx -f ${REFERENCE}/expertgps.gpx -x nuketypes,waypoints,tracks -x transform,wpt=rte,del=y -o gpx -F ${TMPDIR}/transform-wpt.gpx +compare ${TMPDIR}/transform-wpt.gpx ${REFERENCE}/transform-wpt.gpx + + exit 0 diff --git a/transform.c b/transform.c new file mode 100644 index 000000000..4ad51ab53 --- /dev/null +++ b/transform.c @@ -0,0 +1,194 @@ +/* + + Transformation filter for GPS data. + + Copyright (C) 2006 Olaf Klein, o.b.klein@gpsbabel.org + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA + + */ + +#include "defs.h" +#include "filterdefs.h" + +#if FILTERS_ENABLED + +#include + +#define MYNAME "transform" + +static char current_target; +static route_head *current_trk; +static route_head *current_rte; + +static char *opt_routes, *opt_tracks, *opt_waypts, *opt_delete; + +static +arglist_t transform_args[] = { + {"wpt", &opt_waypts, "Transformate track(s) or route(s) into waypoint(s) [R/T].", NULL, + ARGTYPE_STRING, ARG_NOMINMAX}, + {"rte", &opt_routes, "Transformate waypoint(s) or track(s) into route(s) [W/T].", NULL, + ARGTYPE_STRING, ARG_NOMINMAX}, + {"trk", &opt_tracks, "Transformate waypoint(s) or route(s) into tracks(s) [W/R].", NULL, + ARGTYPE_STRING, ARG_NOMINMAX}, + {"del", &opt_delete, "Delete source data after transformation.", "N", + ARGTYPE_BOOL, ARG_NOMINMAX}, + ARG_TERMINATOR +}; + +static void +transform_waypoints(void) +{ + queue *elem, *tmp; + route_head *rte; + + rte = route_head_alloc(); + switch(current_target) { + case 'R': route_add_head(rte); break; + case 'T': track_add_head(rte); break; + } + + QUEUE_FOR_EACH(&waypt_head, elem, tmp) + { + waypoint *wpt = (waypoint *) elem; + + wpt = waypt_dupe(wpt); + switch(current_target) { + case 'R': route_add_wpt(rte, wpt); break; + case 'T': track_add_wpt(rte, wpt); break; + } + } +} + +static void +transform_rte_disp_hdr_cb(const route_head *rte) +{ + if (current_target == 'T') { + current_trk = route_head_alloc(); + track_add_head(current_trk); + if (rte->rte_name && *rte->rte_name) + xasprintf(¤t_trk->rte_desc, "Generated from route %s", rte->rte_name); + } +} + +static void +transform_trk_disp_hdr_cb(const route_head *trk) +{ + if (current_target == 'R') { + current_rte = route_head_alloc(); + route_add_head(current_rte); + if (trk->rte_name && *trk->rte_name) + xasprintf(¤t_rte->rte_desc, "Generated from track %s", trk->rte_name); + } +} + +static void +transform_any_disp_wpt_cb(const waypoint *wpt) +{ + waypoint *temp = waypt_dupe(wpt); + waypt_add(temp); +} + +static void +transform_routes(void) +{ + route_disp_all(transform_rte_disp_hdr_cb, NULL, transform_any_disp_wpt_cb); +} + +static void +transform_tracks(void) +{ + track_disp_all(transform_trk_disp_hdr_cb, NULL, transform_any_disp_wpt_cb); +} + +/******************************************************************************* +* %%% global callbacks called by gpsbabel main process %%% * +*******************************************************************************/ + +static void +transform_init(const char *args) +{ +} + +static void +transform_deinit(void) +{ +} + +static void +transform_process(void) +{ + int delete_after = (opt_delete && (*opt_delete == '1')) ? 1 : 0; + + if (opt_waypts != NULL) { + current_target = 'W'; + switch(toupper(*opt_waypts)) { + case 'R': + transform_routes(); + if (delete_after) route_flush_all_routes(); + break; + case 'T': + transform_tracks(); + if (delete_after) route_flush_all_tracks(); + break; + default: + fatal(MYNAME ": Invalid option value (%s)!\n", opt_waypts); + } + } + if (opt_routes != NULL) { + current_target = 'R'; + switch(toupper(*opt_routes)) { + case 'W': + transform_waypoints(); + if (delete_after) waypt_flush_all(); + break; + case 'T': + transform_tracks(); + if (delete_after) route_flush_all_tracks(); + break; + default: + fatal(MYNAME ": Invalid option value (%s)!\n", opt_routes); + } + } + if (opt_tracks != NULL) { + current_target = 'T'; + switch(toupper(*opt_tracks)) { + case 'W': + transform_waypoints(); + if (delete_after) waypt_flush_all(); + break; + case 'R': + transform_routes(); + if (delete_after) route_flush_all_routes(); + break; + default: + fatal(MYNAME ": Invalid option value (%s)!\n", opt_tracks); + } + } +} + +/*******************************************************************************/ + +filter_vecs_t transform_vecs = { + transform_init, + transform_process, + transform_deinit, + NULL, + transform_args +}; + +/*******************************************************************************/ + +#endif // FILTERS_ENABLED diff --git a/xmldoc/filters/transform.xml b/xmldoc/filters/transform.xml new file mode 100644 index 000000000..76202cda6 --- /dev/null +++ b/xmldoc/filters/transform.xml @@ -0,0 +1,19 @@ + + This filter can be used to convert GPS data between different data types. + + + Not all known and unknown GPS data formats has beed designed on + one common idea. So we have waypoint-only, route-only, track-only + and formats containing more than one of them. + + + To bring such different formats together we've implemented the transform + filter. + + + The following example show you how to create a route from a waypoint table. + gpsbabel -i csv waypts.txt -x transform,rte=wpt -o gpx -F route.gpx + Only the first letter of option value decides which transformation will be done. + Depending on the used option it can be only 'W' for waypoints, 'R' for routes or + 'T' for tracks. + -- 2.30.2